﻿<?php

//downErWeiMa($_GET['starTime'],$_GET['endTime'],$_GET['shengFeng']);

ini_set("display_errors", "On");

downExcelAll();

function downExcelAll(){



	$qure='SELECT tell,CONCAT(shengFen,",",city) AS dizhi,riqi FROM everydaytell  WHERE riqi BETWEEN "'.$_GET['starTime'].'" AND "'.$_GET['endTime'].'"';


	$host='localhost';
	$user='root';
	$password='root';
	$database='weizandata';
	$link=mysqli_connect($host, $user, $password, $database);
	$link->query("set names utf8");
	$result=mysqli_query($link, $qure);
	$arr=mysqli_fetch_all($result, 1);

	//var_dump($arr);

	require_once 'PHPExcel-1.8/Classes/PHPExcel.php';

	$excelFiled=array("名称","公司类别","个人类型","合作意向","来源","阶段","城市","街道","街道 2","手机","手机1","手机2","课程购买意向","课程","技师平台意向","营销拓客意向","产品意向","备注");

	//var_dump($excelFiled);

	$row=1;

	$objPHPExcel=new PHPExcel();

	$objPHPExcel->getActiveSheet()->fromArray($excelFiled,'A1');

	for($i=0;$i<count($arr);$i++){

		//$disCity=$arr['tell'][$i];

	 	$row+=1;

	 	$objPHPExcel->getActiveSheet()->setCellValue('A'.$row, date("Ymd").$arr[$i]['dizhi']);

	 	$objPHPExcel->getActiveSheet()->setCellValue('B'.$row,'person');

	 	$objPHPExcel->getActiveSheet()->setCellValue('C'.$row, '');

	 	$objPHPExcel->getActiveSheet()->setCellValue('D'.$row, '有明确合作意向');

	 	$objPHPExcel->getActiveSheet()->setCellValue('E'.$row, '网上线索');

	 	$objPHPExcel->getActiveSheet()->setCellValue('F'.$row,'电话/微信首次联系');

	 	$objPHPExcel->getActiveSheet()->setCellValue('G'.$row, $arr[$i]['dizhi']);

	 	$objPHPExcel->getActiveSheet()->setCellValue('H'.$row,'');

	 	$objPHPExcel->getActiveSheet()->setCellValue('I'.$row,'');

	 	$objPHPExcel->getActiveSheet()->setCellValue('J'.$row,$arr[$i]['tell']);

	 	$objPHPExcel->getActiveSheet()->setCellValue('K'.$row,'');

	 	$objPHPExcel->getActiveSheet()->setCellValue('L'.$row,'');

	 	$objPHPExcel->getActiveSheet()->setCellValue('M'.$row,'有意向');

	 	$objPHPExcel->getActiveSheet()->setCellValue('N'.$row,'');

	 	$objPHPExcel->getActiveSheet()->setCellValue('O'.$row,'');

	 	$objPHPExcel->getActiveSheet()->setCellValue('P'.$row,'');

	 	$objPHPExcel->getActiveSheet()->setCellValue('Q'.$row,'');

	 	$objPHPExcel->getActiveSheet()->setCellValue('R'.$row,'');

	}

		$objWriter =PHPExcel_IOFactory:: createWriter($objPHPExcel, 'Excel2007');

		$nameFile='电话导入模板'.date("Ymd");

		$objWriter->save("excel/{$nameFile}.xlsx");  // //excel/二维码.xlsx

//}


		header("Location: excel/{$nameFile}.xlsx");

}

?>